package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "套餐管理")
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> queryPage(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("[SetmealController]传过来的setmealPageQueryDTO为：{}",setmealPageQueryDTO);
        PageResult setmealVo=setmealService.queryPage(setmealPageQueryDTO);
        return Result.success(setmealVo);
    }

    /**
     * 增加套餐及套餐中的菜品
     * @param setmealDTO
     * @return
     */
    @RequestMapping
    @ApiOperation("增加套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("传过来的setmealDTO为：{}",setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id){
        log.info("传过来的id为{}",id);
        SetmealVO setmealVO=setmealService.getById(id);
        return Result.success(setmealVO);
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result changeSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐时，传过来的setmealDTO为：{}",setmealDTO);
        setmealService.ChangeSetmal(setmealDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("修改起售状态")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("传过来的status为：{},id为：{}",status,id);
        setmealService.startOrStop(status,id);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("删除套餐表")
    public Result deleteSetmeal(@RequestParam List<Long> ids){
        log.info("传过来的ids为：{}",ids);
        setmealService.deleteSetmeal(ids);
        return Result.success();
    }


}
